import time

import requests

from getSign import get_encrypt_pwd, get_sign

"""
APP: 分享合伙人
http://texu.10039.cc
"""
class RnlFenXiangHeHuoRen:
    baseUrl = 'http://texu.10039.cc'
    deviceInfo = 'PHY110'

    def login(self ,serial_number, pass_word):
        url = f'{self.baseUrl}/txhhr/account/login'
        pass_word = get_encrypt_pwd(pass_word)
        cur_t = str(int(time.time() * 1000))
        ipt = {
            'passWord': pass_word,
            'random': cur_t,
            'randomCode': '',
            'serialNumber': serial_number,
            'token': '',
        }
        sgin = get_sign(ipt, cur_t)
        print('passWord::', pass_word) # 1266f2e9cd2f8570bbad08c17992543e
        print('sgin::', sgin) # E0E2F9ADA3C1797E9E64FDE9C429B0DE
        headers = {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Host': 'texu.10039.cc',
        }
        body = {
            'serialNumber': ipt.get('serialNumber'),
            'passWord': ipt.get('passWord'),
            'randomCode': '',
            'deviceInfo': self.deviceInfo
        }
        params = {
            'token': '',
            'random': cur_t,
            'sgin': sgin,
        }
        try:
            response = requests.post(url=url, params=params, data=body, headers=headers)
            data_json = response.json()
            print(data_json)
        except Exception as e:
            print("异常：：", e)


if __name__ == "__main__":
    RnlFenXiangHeHuoRen = RnlFenXiangHeHuoRen()
    RnlFenXiangHeHuoRen.login('15629827520', '123456')